function [WlfA,WlfB,IAb_set,IBb_set] = postestimation_welfare_trade(II,Par,horizons)

Inc = structvars(II);
for ctr0 = 1:size(Inc,1); eval(Inc(ctr0,:)); end

Param = structvars(Par);
for ctr0 = 1:size(Param,1); eval(Param(ctr0,:)); end

IA = IA_1_pr-(IA_2_rdi+IA_3_rde)+IA_4_wd+IA_5_wf+IA_6_wig+IA_7_trf;
IB = IB_1_pr-(IB_2_rdi+IB_3_rde)+IB_4_wd+IB_5_wf+IB_6_wig+IB_7_trf;

IA_b1 = [IA_1_pr(:,1:time_81) IA_bb1_pr(:,1:end-time_81)]-(IA_2_rdi+IA_3_rde)+IA_4_wd+IA_5_wf+IA_6_wig+IA_7_trf;
IB_b1 = [IB_1_pr(:,1:time_81) IB_bb1_pr(:,1:end-time_81)]-(IB_2_rdi+IB_3_rde)+IB_4_wd+IB_5_wf+IB_6_wig+IB_7_trf;

IA_b2_xi = IA_1_pr-(IA_bb2_xi+IA_3_rde)+IA_4_wd+IA_5_wf+IA_6_wig+IA_7_trf;
IB_b2_xi = IB_1_pr-(IB_bb2_xi+IB_3_rde)+IB_4_wd+IB_5_wf+IB_6_wig+IB_7_trf;

IA_b2 = IA_1_pr-([IA_2_rdi(:,1:time_81) IA_bb2_rdi(:,1:end-time_81)]+IA_3_rde)+IA_4_wd+IA_5_wf+IA_6_wig+IA_7_trf;
IB_b2 = IB_1_pr-([IB_2_rdi(:,1:time_81) IB_bb2_rdi(:,1:end-time_81)]+IB_3_rde)+IB_4_wd+IB_5_wf+IB_6_wig+IB_7_trf;

IA_b3_xe = IA_1_pr-(IA_2_rdi+IA_bb3_xe)+IA_4_wd+IA_5_wf+IA_6_wig+IA_7_trf;
IB_b3_xe = IB_1_pr-(IB_2_rdi+IB_bb3_xe)+IB_4_wd+IB_5_wf+IB_6_wig+IB_7_trf;

IA_b3 = IA_1_pr-(IA_2_rdi+[IA_3_rde(:,1:time_81) IA_bb3_rde(:,1:end-time_81)])+IA_4_wd+IA_5_wf+IA_6_wig+IA_7_trf;
IB_b3 = IB_1_pr-(IB_2_rdi+[IB_3_rde(:,1:time_81) IB_bb3_rde(:,1:end-time_81)])+IB_4_wd+IB_5_wf+IB_6_wig+IB_7_trf;

IA_b4 = IA_1_pr-(IA_2_rdi+IA_3_rde)+[IA_4_wd(:,1:time_81) IA_bb4_wd(:,1:end-time_81)]+IA_5_wf+IA_6_wig+IA_7_trf;
IB_b4 = IB_1_pr-(IB_2_rdi+IB_3_rde)+[IB_4_wd(:,1:time_81) IB_bb4_wd(:,1:end-time_81)]+IB_5_wf+IB_6_wig+IB_7_trf;

IA_b5 = IA_1_pr-(IA_2_rdi+IA_3_rde)+IA_4_wd+[IA_5_wf(:,1:time_81) IA_bb5_wf(:,1:end-time_81)]+IA_6_wig+IA_7_trf;
IB_b5 = IB_1_pr-(IB_2_rdi+IB_3_rde)+IB_4_wd+[IB_5_wf(:,1:time_81) IB_bb5_wf(:,1:end-time_81)]+IB_6_wig+IB_7_trf;

IA_b6 = IA_1_pr-(IA_2_rdi+IA_3_rde)+IA_4_wd+IA_5_wf+[IA_6_wig(:,1:time_81) IA_bb6_wig(:,1:end-time_81)]+IA_7_trf;
IB_b6 = IB_1_pr-(IB_2_rdi+IB_3_rde)+IB_4_wd+IB_5_wf+[IB_6_wig(:,1:time_81) IB_bb6_wig(:,1:end-time_81)]+IB_7_trf;

IA_b7 = IA_1_pr-(IA_2_rdi+IA_3_rde)+IA_4_wd+IA_5_wf+IA_6_wig+[IA_7_trf(:,1:time_81) IA_bb7_trf(:,1:end-time_81)];
IB_b7 = IB_1_pr-(IB_2_rdi+IB_3_rde)+IB_4_wd+IB_5_wf+IB_6_wig+[IB_7_trf(:,1:time_81) IB_bb7_trf(:,1:end-time_81)];

IA_bb = IA_bb1_pr-(IA_bb2_rdi+IA_bb3_rde)+IA_bb4_wd+IA_bb5_wf+IA_bb6_wig+IA_bb7_trf;
IB_bb = IB_bb1_pr-(IB_bb2_rdi+IB_bb3_rde)+IB_bb4_wd+IB_bb5_wf+IB_bb6_wig+IB_bb7_trf;
    
IA_b = [IA(:,1:time_81) IA_bb(:,1:end-time_81)];
IB_b = [IB(:,1:time_81) IB_bb(:,1:end-time_81)];

% Next, _box means factor x has original path! boy and bowfg refer to fixed
% factor in final good production.

IA_bbo = IA_bb1_pr-(IA_bb2_rdi+IA_bb3_rde)+IA_bo4_wd+IA_bo5_wf+IA_bo6_wig+IA_bo7_trf;
IB_bbo = IB_bb1_pr-(IB_bb2_rdi+IB_bb3_rde)+IB_bo4_wd+IB_bo5_wf+IB_bo6_wig+IB_bo7_trf;

IA_bod = IA_bb1_pr-(IA_bb2_rdi+IA_bb3_rde)+IA_bo4_wd+IA_bb5_wf+IA_bo6_wig+IA_bo7_trf;
IB_bod = IB_bb1_pr-(IB_bb2_rdi+IB_bb3_rde)+IB_bo4_wd+IB_bb5_wf+IB_bo6_wig+IB_bo7_trf;

IA_bof = IA_bb1_pr-(IA_bb2_rdi+IA_bb3_rde)+IA_bb4_wd+IA_bo5_wf+IA_bo6_wig+IA_bo7_trf;
IB_bof = IB_bb1_pr-(IB_bb2_rdi+IB_bb3_rde)+IB_bb4_wd+IB_bo5_wf+IB_bo6_wig+IB_bo7_trf;

IA_boy = IA_bb1_pr-(IA_bb2_rdi+IA_bb3_rde)+IA_bo4_wd+IA_bo5_wf+IA_bb6_wig+IA_bo7_trf; 
IB_boy = IB_bb1_pr-(IB_bb2_rdi+IB_bb3_rde)+IB_bo4_wd+IB_bo5_wf+IB_bb6_wig+IB_bo7_trf;


IA_bo    = [IA(:,1:time_81) IA_bbo(:,1:end-time_81)];
IA_bodom = [IA(:,1:time_81) IA_bod(:,1:end-time_81)];
IA_bofrn = [IA(:,1:time_81) IA_bof(:,1:end-time_81)];
IA_bowfg = [IA(:,1:time_81) IA_boy(:,1:end-time_81)];

IB_bo    = [IB(:,1:time_81) IB_bbo(:,1:end-time_81)];
IB_bodom = [IB(:,1:time_81) IB_bod(:,1:end-time_81)];
IB_bofrn = [IB(:,1:time_81) IB_bof(:,1:end-time_81)];
IB_bowfg = [IB(:,1:time_81) IB_boy(:,1:end-time_81)];

% time_81 = 2000;

if psy == 1
    
    for ctr_t = 1:length(horizons)
    
        Wlf_b(ctr_t,1) = sum(exp(-ro*(dt:dt:horizons(ctr_t))).*log(IA_b(time_81+1:time_81+horizons(ctr_t)/dt)));

        Wlf_bB(ctr_t,1) = sum(exp(-ro*(dt:dt:horizons(ctr_t))).*log(IB_b(time_81+1:time_81+horizons(ctr_t)/dt)));
        
    end

    WlfA = Wlf_b;
    WlfB = Wlf_bB;
       
else    
    
    for ctr_t = 1:length(horizons)
    
        Wlf_b(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IA_b(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_b1(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IA_b1(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_b2_xi(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IA_b2_xi(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_b2(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IA_b2(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_b3_xe(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IA_b3_xe(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_b3(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IA_b3(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_b4(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IA_b4(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_b5(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IA_b5(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_b6(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IA_b6(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_b7(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IA_b7(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_bo(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IA_bo(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_bod(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IA_bodom(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_bof(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IA_bofrn(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_boy(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IA_bowfg(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];

        Wlf_bB(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IB_b(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_bB1(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IB_b1(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_bB2_xi(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IB_b2_xi(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_bB2(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IB_b2(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_bB3_xe(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IB_b3_xe(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_bB3(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IB_b3(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_bB4(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IB_b4(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_bB5(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IB_b5(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_bB6(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IB_b6(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_bB7(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IB_b7(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_boB(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IB_bo(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_bodB(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IB_bodom(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_bofB(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IB_bofrn(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        Wlf_boyB(ctr_t,1) = (1-psy)^-1*[sum(exp(-ro*(dt:dt:horizons(ctr_t))).*(IB_bowfg(time_81+1:time_81+horizons(ctr_t)/dt).^(1-psy)))];
        
    end

    WlfA = [Wlf_b,Wlf_b1,Wlf_b2_xi,Wlf_b2,Wlf_b3_xe,Wlf_b3,Wlf_b4,Wlf_b5,Wlf_b6,Wlf_b7,Wlf_bo,Wlf_bod,Wlf_bof,Wlf_boy];
    WlfB = [Wlf_bB,Wlf_bB1,Wlf_bB2_xi,Wlf_bB2,Wlf_bB3_xe,Wlf_bB3,Wlf_bB4,Wlf_bB5,Wlf_bB6,Wlf_bB7,Wlf_boB,Wlf_bodB,Wlf_bofB,Wlf_boyB];
    
    IAb_set = [IA_b;IA_b1;IA_b2_xi;IA_b2;IA_b3_xe;IA_b3;IA_b4;IA_b5;IA_b6;IA_b7];
    IBb_set = [IB_b;IB_b1;IB_b2_xi;IB_b2;IB_b3_xe;IB_b3;IB_b4;IB_b5;IB_b6;IB_b7];

end